package nl.hva.three2learn.authentication;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import nl.hva.three2learn.model.User;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

public class UserAuthenticationDetails implements UserDetails {

	private static final long serialVersionUID = -6271441141293430490L;

	private final User user;
	
	private final List<GrantedAuthority> authorities;
	
	public UserAuthenticationDetails(User user, GrantedAuthority[] authorities) {
		this.user = user;
		this.authorities = Arrays.asList(authorities);
	}
	
	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return authorities;
	}

	@Override
	public String getPassword() {
		return user.getPassword();
	}

	@Override
	public String getUsername() {
		return user.getEmail();
	}

	public User getUser() { 
		return user;
	}
	
	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return false;
	}

	@Override
	public boolean isEnabled() {
		return !user.isDisabled();
	}

}
